
import SchoolAPI from '../api/school.js';

export const School={
   state:{
      schoollist:[],
      school_total_count:0,
      editSchoolStatus:-1,     //插入状态 0失败  1成功  -1不改变
      schoolinfo:[],
      delSchoolStatus:-1,       //删除状态
      schooltype:[
        {value:'1',label:'幼儿园'},
        {value:'2',label:'小学'},
        {value:'3',label:'成人小学'},
        {value:'4',label:'普通初中'},
        {value:'5',label:'职业初中'},
        {value:'6',label:'成人初中'},
        {value:'7',label:'普通高中'},
        {value:'8',label:'职业高中'},
        {value:'9',label:'成人高中'},
        {value:'10',label:'普通大学'},
        {value:'11',label:'本科'},
        {value:'12',label:'大专'}
      ]
   },
   mutations:{
      setSchoolList(state,list){
          state.schoollist=list;
      },
      setSchoolTotalCount(state,total_count){
          state.school_total_count=total_count;
      },
      setEditSchoolStatus(state,status){
          state.editSchoolStatus=status;
      },
      setSchoolInfo(state,info){
          state.schoolinfo=info;
      },
      setDelSchoolStatus(state,status){
          state.delSchoolStatus=status;
      }
   },
   actions:{
      loadSchoolList(context,data){
          SchoolAPI.getSchoolList(data).then(function(response){
              if(response.data.code==1){
                  context.commit('setSchoolList',response.data.list);
                  context.commit('setSchoolTotalCount',response.data.total_count);
              }
          })
      },
      //插入School
      editSchool(context,data){
          SchoolAPI.editSchool(data).then(function(response){
              context.commit('setEditSchoolStatus',response.data.code);
          })
      },
      //获取详情
      loadSchoolInfo(context,data){
          SchoolAPI.getSchoolInfo(data).then(function(response){
              if(response.data.code==1){
                  context.commit('setSchoolInfo',response.data.info);
              }
          })
      },
      //删除
      delSchool(context,data){
          SchoolAPI.delSchool(data).then(function(response){
                context.commit('setDelSchoolStatus',response.data.code);
          })
      }
   },
   getters:{
      getSchoolList:state =>{
         return state.schoollist
      },
      getSchoolTotalCount: state =>{
         return state.school_total_count
      },
      getEditSchoolStatus:state=>{
          return state.editSchoolStatus;
      },
      getSchoolInfo:state => {
          return state.schoolinfo;
      },
      getDelSchoolStatus:state => {
          return state.delSchoolStatus;
      },
      getSchoolType:state => {
          return state.schooltype;
      }
   }
}
